package org.lzy.shop.viewmodel.repository.lmpl

import org.lzy.shop.network.KtorApiService
import org.lzy.shop.response.ListSearch
import org.lzy.shop.response.SearchResponse
import org.lzy.shop.viewmodel.repository.BaseRepository
import org.lzy.shop.viewmodel.repository.SearchRepository

class SearchRepositoryImpl: BaseRepository(), SearchRepository {
    override suspend fun getSearchHot(): MutableList<SearchResponse>? {
        return safeApiCall {
            val response = KtorApiService.getSearchHot()
            handleResponse(response)
        }
    }

    override suspend fun getSearchResult(
        page: Int,
        keyword: String,
        typeId: ArrayList<Int>?,
        order: String,
        sort: String
    ): MutableList<ListSearch>? {
        return safeApiCall {
            val response = KtorApiService.getSearchResult(
                keyword = keyword,
                page = page,
                typeId = typeId,
                order = order,
                sort = sort
            )
            handleResponse(response).list
        }
    }
}